/*
 * Packet.h
 *
 *  Created on: 2.4.2011
 *      Author: Tomas Srna
 */

#ifndef PACKET_H_
#define PACKET_H_

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>

class Packet {
public:
	enum type {RRQ=1, WRQ, DATA, ACK, ERROR};
public:
	type opcode;
	std::string filename;
	std::string mode;
	unsigned short blocknum;
	std::vector<char> data;
	unsigned short errorcode;
	std::string errmsg;
public:
	Packet();
	Packet(const char * buf, int len);
	static std::string t(type opcode);
	void store(std::vector<char>& buf) const;
	void print(std::ostream& logger);
	friend std::ostream& operator <<
			(std::ostream& lhs, const Packet& rhs);
};

#endif /* PACKET_H_ */
